<?php

namespace App\Notifications;

use App\Notifications\Channels\QyWx;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class CommonMessage extends Notification implements ShouldQueue
{
    use Queueable;

    private $message = '';

    private $to_user;

    /**
     * Create a new notification instance.
     *
     * @param $message
     */
    public function __construct($message,$to_user = '@all')
    {
        $this->message = $message;
        $this->to_user = $to_user;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [QyWx::class];
    }

    public function toQyWx()
    {
        $this->message = app()->environment(['local', 'staging']) ? "「测试环境」$this->message" : $this->message;
        return [
            'touser' => $this->to_user,
            'msgtype' => 'text',
            'agentid' => '1000015',
            'text' => [
                'content' => $this->message
            ]
        ];
    }
}
